interface Shape{
    public void draw();
}
interface Color{
    public void fill();
}
class Circle implements Shape{
    public void draw()
    {
        System.out.println("this is Circle");
    }
}

class Rectangle implements Shape{
    public void draw()
    {
        System.out.println("this is Rectangle");
    }
}

class Square implements Shape{
    public void draw()
    {
        System.out.println("this is Square");
    }
}

class Green implements Color{
    public void fill()
    {
        System.out.println("fill with green");
    }
}
class Red implements Color{
    public void fill()
    {
        System.out.println("fill with red");
    }
}
class Blue implements Color{
    public void fill()
    {
        System.out.println("fill with blue");
    }
}

abstract class AbstractFactory{
    abstract Color getColor(String colortype);
    abstract Shape getShape(String shapetype);
}

class ColorFactory extends AbstractFactory{
    Shape getShape(String shapetype)
    {
        return null;
    }
    Color getColor(String colortype)
    {
        if(colortype == null)
        {
            return null;
        }
        if(colortype == "green")
        {
            return new Green();
        }
        if(colortype == "red")
        {
            return new Red();
        }
        if(colortype == "blue")
        {
            return new Blue();
        }
        return null;
    }
}
class ShapeFactory extends AbstractFactory{
    Color getColor(String colortype)
    {
        return null;
    }
    Shape getShape(String shapetype)
    {
        if(shapetype == null)
        {
            return null;
        }
        if(shapetype == "circle")
        {
            return new Circle();
        }
        if(shapetype == "square")
        {
            return new Square();
        }
        if(shapetype == "rectangle")
        {
            return new Rectangle();
        }
        return null;
    }
}


class FactoryProducer{
    AbstractFactory getFactory(String factorytype)
    {
        if(factorytype == null)
        {
            return null;
        }
        if(factorytype == "color")
        {
            return new ColorFactory();
        }
        if(factorytype == "shape")
        {
            return new ShapeFactory();
        }
        return null;
    }
}

public class AbstractFactoryPattern{
   public static void main(String[] args)
   {
      FactoryProducer factoryproducer1 = new FactoryProducer();
      AbstractFactory colorfactory1 = factoryproducer1.getFactory("color");
      Color color1 = colorfactory1.getColor("red");
      color1.fill();

      AbstractFactory shapefactory1 = factoryproducer1.getFactory("shape");
      Shape shape1 = shapefactory1.getShape("circle");
      shape1.draw();
      
      Shape shape2 = shapefactory1.getShape("square");
      shape2.draw();

   }
}




      
